/**
TemplateGame.hpp
Title: Binge Sprite Header File
Descr: Sprite Class

Copyright (c) 2010, Brant Ryan Anderson
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <ORGANIZATION> nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

#ifndef BINGE_SPRITE_HPP
#define BINGE_SPRITE_HPP

#include <iostream>
#include <SFML/Graphics.hpp>
#include "../../binge/core/Timer.hpp"
#include "../../binge/objects/Entity.hpp"
#include "../../binge/utilities/AnimationSet.hpp"
#include "../../binge/utilities/Texture.hpp"
#include "../../binge/utilities/Vector3.hpp"

namespace binge
{

class Sprite : public Entity
{
public:
	//screen position
	Vector3 getPosition(void) { return position; }
	void setPosition(Vector3 pos) { position = pos; }
	void setPosition(double x, double y) { position.Set(x,y,0); }
	double getX() { return position.getX(); }
	double getY() { return position.getY(); }
	void setX(double x) { position.setX(x); }
	void setY(double y) { position.setY(y); }

	//movement velocity
	Vector3 getVelocity() { return velocity; }
	void setVelocity(Vector3 v) { velocity = v; }
	void setVelocity(double x, double y) { velocity.setX(x); velocity.setY(y); }

	//image size
	void setSize(int w, int h) { width = w; height = h; }
	int getWidth() { return width; }
	void setWidth(int value) { width = value; }
	int getHeight() { return height; }
	void setHeight(int value) { height = value; }

	//bool getVisible() { return visible; }
	//void setVisible(bool value) { visible = value; }
    int getFrameWidth(void);
    int getFrameHeight(void);
	//bool getAlive() { return alive; }
	//void setAlive(bool value) { alive = value; }

	int getState() { return state; }
	void setState(int value) { state = value; }

	int getDirection() { return direction; }
	void setDirection(int value) { direction = value; }

	int getColumns() { return animcolumns; }
	void setColumns(int value) { animcolumns = value; }

	int getFrameTimer() { return frametimer; }
	void setFrameTimer(int value) { frametimer = value; }

	int getCurrentFrame() { return curframe; }
	void setCurrentFrame(int value) { curframe = value; }

	int getTotalFrames() { return totalframes; }
	void setTotalFrames(int value) { totalframes = value; }

	int getMoveTimer() { return movetimer; }
	void setMoveTimer(int value) { movetimer = value; }

	std::string getAnimName() { return animName; }
	void setAnimName(std::string value) { animName = value; }

	void addAnimSet(AnimationSet animSet) {	animSetList.push_back(animSet);
											animName = animSetList[animSetList.size()-1].getName();};

public:
	Sprite(void);
	virtual ~Sprite(void);
	bool loadImage(std::string filename, sf::Color transcolor = sf::Color(255,0,255,255));
	void setImage(Texture* tex);
	void move(void);
	void animate(void);
	void draw(void);

protected:
	Texture* image;
	std::vector<AnimationSet> animSetList;
	std::string animName;
	int width, height;
	int animcolumns;
	unsigned int framestart,frametimer;
	unsigned int movestart, movetimer;
	int curframe,totalframes;
	double faceAngle, moveAngle;

private:
	//bool visible;
	//bool alive;
	int lifetimeLength;
	Timer lifetimeTimer;
	Vector3 position;
	Vector3 velocity;
	//int objecttype;
	bool imageLoaded;
	int state;
	int direction;
};

} //namespace

#endif
